<template>
	<view>
		<navbar title="全部评价"></navbar>
		<view class="evaluate-top bgf">
			<view>用户评价</view>
			<view class="type-box flex fww">
				<view class="type-list" :class="{active: typeIndex == index}" v-for="(item, index) in typeList" :key="index" @click="changeType(index)">{{item}}({{typeNums[index]}})</view>
			</view>
		</view>
		<view class="evaluate-box">
			<view class="evaluate-list bgf" v-for="(item, index) in list" :key="index">
				<view class="user-box fa">
					<image class="avatar" :src="item.account.avatar" mode=""></image>
					<view class="flex1">
						<view class="fa jcsb">
							<view class="nickname">{{item.account.name}}</view>
							<view class="fa">
								<uni-rate :size="12" active-color="#FE3134" v-model="item.manner" :readonly="true"/>
								<view class="rate-name">{{item.manner}}分</view>
							</view>
						</view>
						<view class="time">{{item.createTime}}</view>
					</view>
				</view>
				<view class="content">{{item.content}}</view>
				<view class="img-box flex fww" v-if="item.image.length > 0">
					<image :src="row" mode="" v-for="(row, col) in item.image" :key="col" @click="utils.previewImage(item.image, col)"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				typeList: ['全部', '好评', '晒图'],
				typeIndex: 0,
				typeNums: [0, 0, 0],
				page: 1,
				count: 0,
				list: [],
				nodata: 0
			};
		},
		onLoad(options) {
			if(options.id) {
				this.id = options.id
				this.getComment()
			}
		},
		onReachBottom() {
			if(this.list.length < this.count) {
				this.page++
				let type = 0
				if(index == 1) {
					type = 2
				}else if(index == 2) {
					type = 1
				}
				this.getComment()
			}
		},
		methods: {
			changeType(index) {
				this.typeIndex = index
				let type = ''
				if(index == 1) {
					type = 0
				}else if(index == 2) {
					type = 3
				}
				this.getComment(type)
			},
			getComment(t = '') {
				this.api.goodsCommentFunc({
					productId: this.id,
					t: t
				}).then(res => {
					if(res.code == 200) {
						if(res.data.data.rows.length > 0) {
							this.typeNums = []
							this.typeNums.push(res.data.all, res.data.good, res.data.have)
							this.count = res.data.data.total
							this.list = this.page == 1 ? res.data.data.rows : this.list.concat(res.rows)
							this.nodata = this.list.length > 0 ? 0 : 1
							this.list.forEach(item => {
								if(item.image != '') {
									item.image = item.image.split(',')
								}else {
									item.image = []
								}
							})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.evaluate-top{
		margin-top: 16rpx;
		padding: 30rpx 20rpx 2rpx;
		.type-box{
			margin-top: 30rpx;
			.type-list{
				margin-right: 20rpx;
				margin-bottom: 20rpx;
				padding: 0 16rpx;
				height: 40rpx;
				line-height: 40rpx;
				border-radius: 8rpx;
				text-align: center;
				font-size: 24rpx;
				background: #ededed;
				&.active{
					color: #fff;
					background: var(--theme);
				}
			}
		}
	}
	.evaluate-box{
		margin-top: 16rpx;
		padding-bottom: 2rpx;
		.evaluate-list{
			margin-bottom: 16rpx;
			padding: 30rpx 20rpx;
			.user-box{
				.avatar{
					margin-right: 10rpx;
					width: 70rpx;
					height: 70rpx;
					border-radius: 50%;
				}
				.nickname{
					font-size: 26rpx;
				}
				.time{
					margin-top: 4rpx;
					font-size: 22rpx;
					color: #999;
				}
				.rate-name{
					margin-left: 12rpx;
					font-size: 22rpx;
				}
			}
			.content{
				margin-top: 16rpx;
				font-size: 24rpx;
			}
			.img-box{
				image{
					margin-top: 19rpx;
					margin-right: 19rpx;
					width: 224rpx;
					height: 224rpx;
					border-radius: 8rpx;
					&:nth-child(3n){
						margin-right: 0;
					}
				}
			}
		}
	}
</style>
